const blockChainApp = require("../BlockChainApp")
const Config = require("../Config")


// 病例报告合约
module.exports = {
    // 新增处方
    addCheckProject: async function(param){
        var checkProjectContract = await blockChainApp.contracts.CheckProject.deployed()
        //createCheckProjectInfo(string memory _username, uint _checkDate, string memory _checkResult, int32 _status, string memory _doctor, string memory _subject, uint32 _price) 
        return checkProjectContract.createCheckProjectInfo(param.username, param.checkDate, param.checkResult, param.status, param.doctor, param.subject, param.price, param.name, {from: Config.executeAccount})
    },

    // 更新处方
    updateProject: async function(param){
        var checkProjectContract = await blockChainApp.contracts.CheckProject.deployed()
        //updateCheckProjectInfo(uint32 _id, string memory _username, uint _checkDate, string memory _checkResult, int32 _status, string memory _doctor, string memory _subject, uint32 _price) 
        return checkProjectContract.updatePrescription(param.id, param.username, param.checkDate, param.checkResult, param.status, param.doctor, param.subject, param.price, param.name, {from: Config.executeAccount})
    },

    // 查看所有处方
    getAllProject: async function(param){
        var checkProjectContract = await blockChainApp.contracts.CheckProject.deployed()
        return checkProjectContract.findAllCheckProjectInfo.call()
    },

    // 条件查询处方
    getProjectWithCondition: async function(param){
        var checkProjectContract = await blockChainApp.contracts.CheckProject.deployed()
        //string memory _username, uint _startCheckDate, uint _endCheckDate, string memory _doctor, string memory _subjec
        return checkProjectContract.findCheckProjectInfo.call(param.username, param.startCheckDate, param.endCheckDate, param.doctor, param.subject)
    }
}